package com.huawei.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.huawei.constant.MessageConstant;
import com.huawei.entity.PageResult;
import com.huawei.entity.QueryPageBean;
import com.huawei.entity.Result;
import com.huawei.pojo.CheckItem;
import com.huawei.service.CheckItemService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/checkItem")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;

    @RequestMapping("/add")
    public Result add(@RequestBody CheckItem checkItem) {
        try {
            checkItemService.add(checkItem);
        }catch (Exception e) {
            return  new Result(false, MessageConstant.ADD_CHECKITEM_FAIL);
        }
        return  new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        return  checkItemService.findPage(queryPageBean);
    }


    @RequestMapping("/delete")
    public Result delete(Integer id) {
        try {
            checkItemService.delete(id);
        } catch (Exception e) {
            return  new Result(false,MessageConstant.DELETE_CHECKITEM_FAIL);
        }

        return  new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }


    @RequestMapping("/findByCheckItemId")
    public Result findByCheckItemId(Integer id) {
        try {
            CheckItem  checkItem =   checkItemService.findByCheckItemId(id);
            return new Result(true,MessageConstant.QUERY_CHECKGROUP_SUCCESS,checkItem);
        } catch (Exception e) {
            //服务调用失败
            return  new Result(false,MessageConstant.QUERY_CHECKITEM_FAIL);
        }
    }


    @RequestMapping("/editCheckItem")
    public Result editCheckItem(@RequestBody CheckItem checkItem) {
        try {
            checkItemService.editCheckItem(checkItem);
        } catch (Exception e) {
          return   new Result(false,MessageConstant.EDIT_CHECKITEM_FAIL);
        }
        return  new Result(true,MessageConstant.EDIT_CHECKITEM_SUCCESS);

    }
}
